package com.cpfmat.common;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class MailPropertyUtil {
	private static Properties props;
	static {
		loadProps();
	}

	synchronized static private void loadProps() {
		LogUtils.info("开始加载properties文件内容.......");
		props = new Properties();
		InputStream in = null;
		try {
			in = MailPropertyUtil.class.getClassLoader().getResourceAsStream("mail.properties");
			props.load(in);
		} catch (FileNotFoundException e) {
			LogUtils.error("mail.properties文件未找到");
		} catch (IOException e) {
			LogUtils.error("出现IOException");
		} finally {
			try {
				if (null != in) {
					in.close();
				}
			} catch (IOException e) {
				LogUtils.error("mail.properties文件流关闭出现异常");
			}
		}
		LogUtils.info("加载properties文件内容完成...........");
		LogUtils.info("properties文件内容：" + props);
	}

	public static String getProperty(String key) {
		if (null == props) {
			loadProps();
		}
		return props.getProperty(key);
	}

	public static String getProperty(String key, String defaultValue) {
		if (null == props) {
			loadProps();
		}
		return props.getProperty(key, defaultValue);
	}
}
